package com.demo.adapter;

/**
 * @Author likz
 * @Date 2025/7/24 13:48
 * @Description 对象适配器
 * 对象适配器模式可釆用将现有组件库中已经实现的组件引入适配器类中，该类同时实现当前系统的业务接口。
 *
 **/
public class SDAdapterCard implements SDCard{

    private TFCard tfCard;


    public SDAdapterCard(TFCard tfCard) {
        this.tfCard = tfCard;
    }

    @Override
    public String readSD() {
        System.out.println("SDCard read tf card ");
        return tfCard.readTF();
    }

    @Override
    public void writeSD(String msg) {
        System.out.println("SDCard write tf card ");
        tfCard.writeTF(msg);
    }



    public static void main(String[] args) {
        Computer computer = new Computer();
        SDCard sdCard = new SDCardImpl();
        System.out.println(computer.readSD(sdCard));

        System.out.println("------------");

        TFCard tfCard = new TFCardImpl();
        SDAdapterCard adapter = new SDAdapterCard(tfCard);
        System.out.println(computer.readSD(adapter));
    }

}
